package xyz.dava.file.spring.boot.autoconfigure.client;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import xyz.dava.file.FileClient;
import xyz.dava.file.impl.BaseFileClient;
import xyz.dava.file.impl.aliyun.AliOssFileClient;
import xyz.dava.file.impl.local.LocalFileClient;

public class FileClientConfiguration {


    private static final String PRIMARY_CLIENT_PREFIX = "dava.file.primary";
    private static final String LOCAL_CLIENT_PREFIX = "dava.file.local";
    private static final String ALIYUN_CLIENT_PREFIX = "dava.file.aliyun";


    @Bean
    @Primary
    @ConfigurationProperties(PRIMARY_CLIENT_PREFIX)
    @ConditionalOnMissingBean
    public FileClient fileClient(ApplicationContext context) {
        return new BaseFileClient(context);
    }

    @Bean
    @ConfigurationProperties(LOCAL_CLIENT_PREFIX)
    @ConditionalOnProperty(prefix = LOCAL_CLIENT_PREFIX, name = "enabled")
    @ConditionalOnMissingBean
    public LocalFileClient localFileClient() {
        return new LocalFileClient();
    }

    @Bean
    @ConfigurationProperties(ALIYUN_CLIENT_PREFIX)
    @ConditionalOnProperty(prefix = ALIYUN_CLIENT_PREFIX, name = "enabled")
    @ConditionalOnMissingBean
    public AliOssFileClient aliOssFileClient() {
        return new AliOssFileClient();
    }

}
